﻿Imports DTO
Imports System.Data.SqlClient
Public Class NhaCungCapDAO

    Public Shared Function LayDSNhaCungCapCbx() As DataTable
        Return CKetNoi.GetData("select MaNhaCungCap, TenNhaCungCap from NhaCungCap")
    End Function

    Public Shared Function LayDSNhaCungCap() As DataTable
        Return CKetNoi.GetData("LayDSNhaCungCap")
    End Function

    Public Shared Function ThemNhaCungCap(ncc As NhaCungCapDTO) As Integer
        Dim kt As Integer
        Dim lst As New List(Of SqlParameter)
        lst.Add(New SqlParameter("@tenKH", ncc.TenNhaCungCap))
        lst.Add(New SqlParameter("@maKV", ncc.MaKhuVuc))
        lst.Add(New SqlParameter("@dc", ncc.DiaChi))
        lst.Add(New SqlParameter("@mst", ncc.MaSoThue))
        lst.Add(New SqlParameter("@dt", ncc.DienThoai))
        lst.Add(New SqlParameter("@tk", ncc.TaiKhoan))
        lst.Add(New SqlParameter("@fax", ncc.Fax))
        lst.Add(New SqlParameter("@dd", ncc.DiDong))
        lst.Add(New SqlParameter("@web", ncc.TrangWEB))
        lst.Add(New SqlParameter("@nganhang", ncc.NganHang))
        lst.Add(New SqlParameter("@email", ncc.Email))
        lst.Add(New SqlParameter("@ghno", ncc.GioiHanNo))
        lst.Add(New SqlParameter("@ck", ncc.ChiecKhau))
        lst.Add(New SqlParameter("@nguoilh", ncc.NguoiLienHe))
        lst.Add(New SqlParameter("@maTT", ncc.MaTrangThai))
        lst.Add(New SqlParameter("@cv", ncc.ChucVu))

        kt = CKetNoi.ExecQueryStoreProc("ThemNhaCungCap", lst)
        Return kt
    End Function

    Public Shared Function CapNhatNhaCungCap(ncc As NhaCungCapDTO) As Integer
        Dim kt As Integer
        Dim lst As New List(Of SqlParameter)
        lst.Add(New SqlParameter("@maNCC", ncc.MaNhaCungCap))
        lst.Add(New SqlParameter("@tenNCC", ncc.TenNhaCungCap))
        lst.Add(New SqlParameter("@maKV", ncc.MaKhuVuc))
        lst.Add(New SqlParameter("@dc", ncc.DiaChi))
        lst.Add(New SqlParameter("@mst", ncc.MaSoThue))
        lst.Add(New SqlParameter("@dt", ncc.DienThoai))
        lst.Add(New SqlParameter("@tk", ncc.TaiKhoan))
        lst.Add(New SqlParameter("@fax", ncc.Fax))
        lst.Add(New SqlParameter("@dd", ncc.DiDong))
        lst.Add(New SqlParameter("@web", ncc.TrangWEB))
        lst.Add(New SqlParameter("@nganhang", ncc.NganHang))
        lst.Add(New SqlParameter("@email", ncc.Email))
        lst.Add(New SqlParameter("@ghno", ncc.GioiHanNo))
        lst.Add(New SqlParameter("@ck", ncc.ChiecKhau))
        lst.Add(New SqlParameter("@nguoilh", ncc.NguoiLienHe))
        lst.Add(New SqlParameter("@maTT", ncc.MaTrangThai))
        lst.Add(New SqlParameter("@cv", ncc.ChucVu))

        kt = CKetNoi.ExecQueryStoreProc("CapNhatNhaCungCap", lst)
        Return kt
    End Function

    Public Shared Function XoaNhaCungCap(ncc As NhaCungCapDTO) As Integer

        Dim kt As Integer
        Dim lst As New List(Of SqlParameter)
        lst.Add(New SqlParameter("@maNCC", ncc.MaNhaCungCap))

        kt = CKetNoi.ExecQueryStoreProc("XoaNhaCungCap", lst)
        Return kt
    End Function

    Public Shared DongKetNoi As System.Data.SqlClient.SqlConnection = CKetNoi.Connect

    Public Shared Sub LayMaNhaCungCapCbx(ByVal makh As String, ByRef makv As String)

        DongKetNoi.Open()

        Dim cmd As New SqlCommand
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "LayMaNhaCungCapCbx"
        cmd.Connection = DongKetNoi


        Dim para As SqlParameter

        para = New System.Data.SqlClient.SqlParameter("macc", SqlDbType.VarChar, 7)
        para.Direction = ParameterDirection.Input
        para.Value = makh
        cmd.Parameters.Add(para)

        para = New System.Data.SqlClient.SqlParameter("makv", SqlDbType.VarChar, 7)
        para.Direction = ParameterDirection.Output
        cmd.Parameters.Add(para)

        cmd.ExecuteNonQuery()

        makv = cmd.Parameters("makv").Value

        DongKetNoi.Close()

    End Sub

End Class
